package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_TEAM_VIEW,desc = "队伍查看")
public class DouLuoDaLuGetTeamCmd extends AbstractCommand {

    long teamId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DouLuoDaLuProto.DouLuoDaLuGetTeamInfoReqMsg reqMsg = DouLuoDaLuProto.DouLuoDaLuGetTeamInfoReqMsg.parseFrom(packet.getBytes());
        teamId = reqMsg.getTeamId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(teamId <= 0){
            ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
            return;
        }
        if ((ret = DouLuoDaLuMgr.canEntryActivity(player)) != 0) return;

        DouLuoDaLuProto.DouLuoDaLuGetTeamInfoCrossReqMsg.Builder crossReq = DouLuoDaLuProto.DouLuoDaLuGetTeamInfoCrossReqMsg.newBuilder();
        crossReq.setActivityId(DouLuoDaLuMgr.getActivityInfo().getActivityId());
        crossReq.setTeamId(teamId);
        player.sendUnionActivityGroupPacket(Protocol.C_DOU_LUO_DA_LU_TEAM_VIEW, crossReq, crossReq.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            DouLuoDaLuProto.DouLuoDaLuGetTeamInfoRespMsg.Builder respMsg = DouLuoDaLuProto.DouLuoDaLuGetTeamInfoRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_DOU_LUO_DA_LU_TEAM_VIEW, respMsg);
        }
    }
}
